/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validaciones;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Administrador
 */
@FacesValidator(value = "claveDoble")
public class ClaveDobleValidador implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        /*
         * ExpressionFactory expressionFactory =
         * context.getApplication().getExpressionFactory(); ValueExpression ve =
         * expressionFactory.createValueExpression(context.getELContext(),"#{usuario.clave}",String.class);
         * String value1 = (String) ve.getValue(context.getELContext());
         * if(!value.equals(value1)){ context.addMessage("clave2", new
         * FacesMessage("Es diferente!!!!!!")); }
         */
        UIComponent caja = component.getParent().findComponent("clave");
        UIInput cajaInput = (UIInput) caja;
        Object value1 = cajaInput.getValue();
        if (!value1.equals(value)) {
            context.addMessage("clave2", new FacesMessage("Es diferente!!!!!!"));
        }
    }
}
